﻿@using TomNet.IMSC.Model.DbModels.NewHouse;
@{
    Layout = null;
    var entity = ViewData["entity"] as Buildings;
    //渠道人员
    var channel = ViewData["channel"] as SelectList;
    //驻场人员
    var inThefield = ViewData["inThefield"] as SelectList;
    //楼盘类型
    var BuildingType = ViewData["BuildingType"] as SelectList;
}

<!DOCTYPE html>


<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="~/Content/Css/animate.css" rel="stylesheet">
    <link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
    <title>EditList</title>
    <link href="/Content/Css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Content/common.css" rel="stylesheet">  
    <link href="~/Content/Css/plugins/multiselect/bootstrap-multiselect.css" rel="stylesheet" />
    <style>
        .ibox {
            margin-bottom: 0px;
        }
            

        .multiselect-container input[type="checkbox"] {
            margin-top: 7px;
        }
        .pull-left {
            padding-left:0px;
        }
         /*.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 ,
        .col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12,
        .btn-group {
            border-style: solid;
            border-width: 1px;
            border-color: #000;
        }*/
         #SMLabel {
             width: 105px;
         }

         #SMDiv {
             width: 720px;
             padding-left: 0px;
             padding-right: 0px;
         }
    </style>
</head>
<body>
    <div class="wrapper wrapper-content animated fadeInRight">
        <form class="form-horizontal m-t" id="mainForm">  

            <input type="hidden" id="Id" name="Id" value="@entity.Id" />
            <input type="hidden" id="pr" name="pr" value=@entity.Province />@*省*@
            <input type="hidden" id="ci" name="ci" value=@entity.City />@*市*@
            <input type="hidden" id="ar" name="ar" value=@entity.District />@*区*@

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-3 control-label">楼盘名称：</label>
                        <div class="col-xs-9">
                            <input id="Name" name="Name" type="text" class="form-control" value="@entity.Name">
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请填写楼盘名称</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-3 control-label">楼盘省份：</label>
                        <div class="col-xs-9">
                            <select class="form-control" name="Province" id="Province">
                                <option value="">请选择省</option> 
                            </select>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择省份</span>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-3 control-label">楼盘城市：</label>
                        <div class="col-xs-9">
                            <select class="form-control" name="City" id="City">
                                <option value="">请选择市</option>
                            </select>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择城市</span>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-3 control-label">楼盘地区：</label>
                        <div class="col-xs-9">
                            <select class="form-control" name="District" id="District">
                                <option value="">请选择区</option>
                            </select>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择地区</span>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-3 control-label">楼盘地址：</label>
                        <div class="col-xs-9">
                            <input id="Address" name="Address" type="text" class="form-control" value="@entity.Address">
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请输入楼盘地址</span>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6"> 
                    <div class="form-group">
                        <label class="col-xs-3 control-label">楼盘类型：</label>
                        <div class="col-xs-9">
                            <select class="form-control input-sm" name="BuildingTypeID" id="BuildingTypeID" multiple="multiple">   
                            </select>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择楼盘类型</span>
                    </div> 
                    <div class="form-group">
                        <label class="col-xs-3 control-label">驻场人员：</label>
                        <div class="col-xs-9">
                            <select class="form-control" name="StationedStaffID" id="StationedStaffID">
                                @foreach (SelectListItem item in inThefield.Items)
                                {
                                    <option value='@item.Value' @(entity.MediumOfCommunicationStaffID == Convert.ToInt32(item.Value) ? "selected" : "")>@(item.Text)</option>
                                }
                            </select>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择渠道人员</span>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-3 control-label">渠道人员：</label>
                        <div class="col-xs-9">
                            <select class="form-control" name="MediumOfCommunicationStaffID" id="MediumOfCommunicationStaffID">
                                @foreach (SelectListItem item in channel.Items)
                                {
                                    <option value='@item.Value' @(entity.MediumOfCommunicationStaffID == Convert.ToInt32(item.Value) ? "selected" : "")>@(item.Text)</option>
                                }
                            </select>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择驻场人员</span>
                    </div> 
                    <div class="form-group">
                        <label class="col-xs-3 control-label">佣金帐期：</label>
                        <div class="col-xs-9">
                            <input id="CommissionAccount" name="CommissionAccount" value="@entity.CommissionAccount" type="text" class="form-control">
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请填写佣金帐期</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-3 control-label">售价：</label>
                        <div class="col-xs-9">
                            <input id="SellingPrice" name="SellingPrice" type="text" class="form-control" value="@entity.SellingPrice">
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请输入售价</span>
                        </div>
                    </div> 
                    @*<div class="form-group">
                        <label class="col-xs-3 control-label">租价：</label>
                        <div class="col-xs-9">
                            <input id="LeasePrice" name="LeasePrice" type="text" class="form-control" value="@entity.LeasePrice">
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请输入租价</span>
                        </div>
                    </div>*@ 
                </div>
            </div> 

            <div class="form-group">
                <label class="col-xs-2 control-label" id="SMLabel">楼盘说明：</label>
                <div class="col-xs-10" id="SMDiv">
                    <input id="Remark" name="Remark" value="@entity.Remark" type="text" placeholder="说明" class="form-control">
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请输入楼盘说明</span>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group" style="margin-bottom:0px;padding-top:20px">
                        <div class="col-xs-3">

                        </div>
                        <div class="col-xs-9">
                            <button id="submit" class="btn btn-primary pull-right" type="submit">
                                <i class="fa fa-check"></i>&nbsp;提&nbsp;交
                            </button>
                        </div>
                    </div>

                </div>
            </div>
        </form>
    </div>


    <!-- 全局js -->
    <script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
    <script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
    <!-- jQuery Validation plugin javascript-->
    <script type="text/javascript" src="~/Scripts/plugins/validate/jquery.validate.min.js"></script>
    <script type="text/javascript" src="~/Scripts/plugins/validate/messages_zh.min.js"></script>
    <script type="text/javascript" src="~/Scripts/Extensions/ExtValidator.js"></script>

    <!-- layer javascript -->
    <script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>
    <script src="/Scripts/plugins/iCheck/icheck.min.js"></script>

    <script src="~/Scripts/plugins/multiselect/bootstrap-multiselect.js"></script>
    <script type="text/javascript">
        $(function () {


            //楼盘类型多选框 
            GetBuidings(@entity.Id);
            //$('#BuildingTypeID').multiselect({
            //    buttonClass: 'btn btn-link',//显示按钮style
            //    buttonWidth: '300px',//按钮宽度
            //    inheritClass: true,//继承原来select的button的class
            //    selectAllNumber: false,//true显示allselect（6）,false显示allselect
            //});


            GetProvince();//加载省份  
            $("#Province").change(function () { GetCity() });//加载城市  
            $("#City").change(function () { GetDistrict() });//加载区县

            var icon = "<i class='fa fa-times-circle'></i> ";
            var validator = $("#mainForm").validate({
                rules: { 
                    Name: { required: true, },
                    District: { required: true, }
                },
                messages: {
                    Name: { required: icon + "请输入楼盘名称", },
                    District: { required: icon + "请选择地区", }
                },
                submitHandler: function (form) {
                    $.ajax({
                        url: "/NewHouse/Buildings/EditListAsync",
                        type: "post",
                        dataType: "json",
                        data: $('#mainForm').serialize(),
                        success: function (data) {
                            //Info,Success,Warning,Error
                            var type = data.type;
                            if (type == 1) {
                                layer.msg(data.content, { icon: 6, time: 2000 },
                                    function () {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    });

                            } else {
                                layer.msg(data.content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }
            });
        });

        //楼盘类型多选框 
        function GetBuidings(id) {
            console.log(id);
            $.getJSON(
                "/NewHouse/Buildings/GetBuildingsTypeEdit",
                {
                    did: id
                },
                function (data) {
                    console.log(data);
                    $("#BuildingTypeID").find("option").remove();
                    $("#BuildingTypeID").multiselect("destroy").multiselect({
                        buttonClass: 'btn btn-link',//显示按钮style
                        buttonWidth: '300px',//按钮宽度
                        inheritClass: true,//继承原来select的button的class
                        selectAllNumber: false,//true显示allselect（6）,false显示allselec
                    });
                    $.each(data, function (i, item) {
                        if (item["number"] > 0) {
                            $("<option></option>").val(item["id"]).text(item["name"]).attr("selected", true).appendTo($("#BuildingTypeID"));


                            $("#BuildingTypeID").multiselect("destroy").multiselect({
                                buttonClass: 'btn btn-link',//显示按钮style
                                buttonWidth: '300px',//按钮宽度
                                inheritClass: true,//继承原来select的button的class
                                selectAllNumber: false,//true显示allselect（6）,false显示allselec
                            });
                        }
                        else {
                            $("<option></option>").val(item["id"]).text(item["name"]).appendTo($("#BuildingTypeID"));


                            $("#BuildingTypeID").multiselect("destroy").multiselect({
                                buttonClass: 'btn btn-link',//显示按钮style
                                buttonWidth: '300px',//按钮宽度
                                inheritClass: true,//继承原来select的button的class
                                selectAllNumber: false,//true显示allselect（6）,false显示allselec
                            });
                        }


                    });
                });
        }
        function GetProvince() {
            $("#Province").empty();//清空省份SELECT控件  
            $.getJSON("/NewHouse/Buildings/GetProvincelist", function (data) {
                $.each(data, function (i, item) {
                    if (item["id"] == $("#pr").val()) { 
                        console.log($("#pr").val());
                        $("<option></option>").val(item["id"]).text(item["name"]).attr("selected", true).appendTo($("#Province"));
                    }
                    else {
                        $("<option></option>").val(item["id"]).text(item["name"]).appendTo($("#Province"));
                    }

                })
                GetCity();
            });
        } 
        function GetCity() {
            $("#City").empty();//清空城市SELECT控件  
            $.getJSON(
            "/NewHouse/Buildings/GetCitylist",
            { pid: $("#Province").val() },
            function (data) {
                $.each(data, function (i, item) {
                    if (item["id"] == $("#ci").val()) {
                        console.log($("#ci").val());
                        $("<option></option>").val(item["id"]).text(item["name"]).attr("selected", true).appendTo($("#City"));
                    }
                    else {
                        $("<option></option>").val(item["id"]).text(item["name"]).appendTo($("#City"));
                    }

                })
                GetDistrict();
            });
        }
        function GetDistrict() {
            $("#District").empty();//清空区县SELECT控件  
            $.getJSON(
                "/NewHouse/Buildings/GetDistrictlist",
                {
                    cid: $("#City").val()
                },
                function (data) {
                    $.each(data, function (i, item) {
                        if (item["id"] == $("#ar").val()) {
                            console.log($("#ar").val());
                            $("<option></option>").val(item["id"]).text(item["name"]).attr("selected", true).appendTo($("#District"));
                        }
                        else {
                            $("<option></option>").val(item["id"]).text(item["name"]).appendTo($("#District"));
                        }

                    })
                });
        }
    </script>
</body>
</html>
